package a2_linkedlist.doublelinkedlist;
/**
 * 测试双向链表
 */
public class TestDoubleLinkedList {
    public static void main(String[] args) {
        DoubleLinkedList fly = new DoubleLinkedList();
        /** 增 **/
        System.out.println("/** 增 **/");
        fly.addFirst(2);
        fly.addFirst(1);
        //1 -> 2 -> NULL
        System.out.println(fly);
        fly.addLast(3);
        //1 -> 2 -> 3 -> NULL
        fly.addIndex(1,4);
        //1 -> 4 -> 2 -> 3 -> NULL
        fly.addIndex(3,5);
        //1 -> 4 -> 2 -> 5 -> 3 -> NULL
        System.out.println(fly);

        /** 查 **/
        System.out.println("/** 查 **/");
        System.out.println("索引是3的元素值为 " + fly.get(3));
        System.out.println("判断链表中有无值为2的节点：" + fly.contains(2));

        /** 改 **/
        System.out.println("/** 改 **/");
        System.out.println("链表中索引为2的节点修改前的值为 "+fly.set(2,4));
        //1 -> 4 -> 4 -> 5 -> 3 -> NULL
        System.out.println(fly);

        /** 删 **/
        System.out.println("/** 删 **/");
        fly.removeIndex(2);
        //1 -> 4 -> 5 -> 3 -> NULL
        System.out.println(fly);
        fly.removeIndex(3);
        //1 -> 4 -> 5 -> NULL
        System.out.println(fly);
        fly.addIndex(1,4);
        fly.addLast(4);
        //1 -> 4 -> 4 -> 5 -> 4 -> NULL
        fly.removeValueOnce(4);
        //1 -> 4 -> 5 -> 4 -> NULL
        System.out.println(fly);
        fly.removeValueAll(4);
        //1 -> 5 -> NULL
        System.out.println(fly);
    }
}
